﻿namespace KinonekoSoftware.Extensions.Collections
{
    partial class CollectionStatic
    {
        
        
        //-------------------------------------------------------------
        //
        //          RemoveMany
        //
        //-------------------------------------------------------------



        #region RemoveMany

        /// <summary>
        /// 为集合提供批量添加功能
        /// </summary>
        /// <param name="collection">指定目标集合</param>
        /// <param name="source">要添加的数据源</param>
        /// <param name="clear">是否清除原有的数据</param>
        /// <typeparam name="T">具体的数据类型</typeparam>
        public static void RemoveMany<T>(this Stack<T> collection, IEnumerable<T> source, bool clear)
        {
            if (collection is null ||
                source is null)
            {
                return;
            }

            if (clear)
            {
                collection.Clear();
            }

            foreach (var item in source)
            {
                collection.Push(item);
            }
        }

        /// <summary>
        /// 为集合提供批量添加功能
        /// </summary>
        /// <param name="collection">指定目标集合</param>
        /// <param name="source">要添加的数据源</param>
        /// <param name="clear">是否清除原有的数据</param>
        /// <typeparam name="T">具体的数据类型</typeparam>
        public static void RemoveMany<T>(this Queue<T> collection, IEnumerable<T> source, bool clear)
        {
            if (collection is null ||
                source is null)
            {
                return;
            }

            if (clear)
            {
                collection.Clear();
            }

            foreach (var item in source)
            {
                collection.Enqueue(item);
            }
        }

        /// <summary>
        /// 为集合提供批量添加功能
        /// </summary>
        /// <param name="collection">指定目标集合</param>
        /// <param name="source">要添加的数据源</param>
        /// <param name="clear">是否清除原有的数据</param>
        /// <typeparam name="T">具体的数据类型</typeparam>
        public static void RemoveMany<T>(this HashSet<T> collection, IEnumerable<T> source, bool clear)
        {
            if (collection is null ||
                source is null)
            {
                return;
            }

            if (clear)
            {
                collection.Clear();
            }

            foreach (var item in source)
            {
                collection.Remove(item);
            }
        }

        /// <summary>
        /// 为集合提供批量添加功能
        /// </summary>
        /// <param name="collection">指定目标集合</param>
        /// <param name="source">要添加的数据源</param>
        /// <param name="clear">是否清除原有的数据</param>
        /// <typeparam name="T">具体的数据类型</typeparam>
        public static void RemoveMany<T>(this ICollection<T> collection, IEnumerable<T> source, bool clear)
        {
            if (collection is null ||
                source is null)
            {
                return;
            }

            if (clear)
            {
                collection.Clear();
            }

            foreach (var item in source)
            {
                collection.Remove(item);
            }
        }

        #endregion
    }
}